import * as constants  from './constants'
import axios from 'axios'
import {fromJS} from 'immutable'

export const searchFocus = () =>({
  type: constants.SERACH_FOCUS
})

export const searchBlur = () =>({
  type: constants.SERACH_BLUR
})

export const mouseEnter = () =>({
  type: constants.MOUSE_ENTER
})

export const mouseLeave = () =>({
  type: constants.MOUSE_LEAVE
})


export const changePage = (page) =>({
  type: constants.CHANGE_PAGE,
  page
})




const changList = (data) => ({
  type: constants.CHANGR_LIST,
  // fromJS处理
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10 )
})




export const getList = () =>{
  return (dispatch) => {
    axios.get('/api/headerList.json').then((res) => {
      const data = res.data
      dispatch(changList(data.data))
    }).catch(()=>{
      console.log('error')
    })
  }
}